<template>
	<view class="main">
		<view class="form">
			<view class="list">
				<i class="iconfont icon-youjian"></i><input type="text" v-model="phone" placeholder="请输入手机号">
			</view>
			<view class="yzm">
				<view class="yzmli">
					<i class="iconfont icon-yanzhengma"></i><input type="text" v-model="code" placeholder="请输入验证码">
				</view>
				<view class="yzmbtn" v-if="btnDisabled==0" @click="handcapcha">获取验证码</view>
				<view class="yzmbtn" v-if="btnDisabled==1">
					等待{{second}}秒
				</view>
			</view>
			<view class="list">
				<i class="iconfont icon-mima"></i><input type="password" v-model="pwd" placeholder="请输入密码">
			</view>
			<view class="nav">
				<navigator url="../login/login">登录</navigator>
			</view>
			<view class="btn" @click="handregister">
				确认修改
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				phone: '',
				pwd: '',
				code: '',
				btnDisabled: 0,
				second: 60,
			}
		},
		methods: {
			//提示
			showToas(name) {
				uni.showToast({
					title: name,
					icon: "none",
					mask: true,
					duration: 600
				})
				return;
			},
			//获取验证码
			handcapcha() {
				if (this.phone == false) {
					this.showToas("请填写电话")
					return;
				}
				global.$http.request({
					url: '/api/rider_login/forget_yzm',
					data: {
						phone: this.phone,
					},
				}).then(res => {
					uni.showToast({
						title: res.data.msg,
						icon: "none",
						mask: true,
						duration: 1000
					})
					if (res.data.code == 0) {
						this.timer()
					}
				})
			},
			// 倒计时
			timer() {
				this.btnDisabled = 1
				var interval = setInterval(() => {
					let times = --this.second
					this.second = times < 10 ? '0' + times : times //小于10秒补 0
				}, 1000)
				setTimeout(() => {
					clearInterval(interval)
					this.second = 60
					this.btnDisabled = 0
				}, 60000)
			},
			handregister() {
				global.$http.request({
					url: '/api/rider_login/forget',
					data: {
						phone: this.phone,
						pwd: this.pwd,
						code: this.code,
					}
				}).then(res => {
					if (res.data.code == 0) {
						uni.showToast({
							title: res.data.msg,
							icon: "none",
							mask: true,
							duration: 1000
						})
						setTimeout(function() {
							uni.navigateTo({
								url: '../login/login'
							})
						}, 1000)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {

		.main {
			width: 750rpx;
			height: 100%;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: space-between;

			.form {
				width: 600rpx;
				height: 700rpx;
				margin-top: 40%;
				background: #FFFFFF;
				border-radius: 20rpx;
				box-shadow: 0rpx 2rpx 20rpx 0rpx rgba(116, 116, 116, 0.3);
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;

				.list {
					width: 400rpx;
					height: 76rpx;
					border: 2rpx solid #1DBE61;
					border-radius: 38rpx;
					margin-top: 55rpx;
					display: flex;
					align-items: center;
					padding: 0 20rpx;

					.iconfont {
						margin: 0 5rpx;
						width: 40rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 30rpx;
						flex-shrink: 0;
					}

					input {
						width: 100%;
						font-size: 28rpx;
					}
				}

				.yzm {
					width: 400rpx;
					height: 76rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					margin-top: 55rpx;

					.yzmli {
						width: 255rpx;
						height: 76rpx;
						border: 2rpx solid #1DBE61;
						border-radius: 38rpx 0 0 38rpx;
						display: flex;
						align-items: center;
						padding: 0 20rpx;

						.iconfont {
							margin: 0 5rpx;
							width: 40rpx;
							display: flex;
							align-items: center;
							justify-content: center;
							font-size: 30rpx;
							flex-shrink: 0;
						}

						input {
							width: 100%;
							font-size: 28rpx;
						}
					}

					.yzmbtn {
						width: 140rpx;
						height: 76rpx;
						border: 2rpx solid #1DBE61;
						border-radius: 0 38rpx 38rpx 0;
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 24rpx;
						color: #666666;
					}
				}

				.nav {
					width: 400rpx;
					margin-top: 20rpx;
					display: flex;
					flex-direction: row-reverse;
					font-size: 26rpx;
					color: #808080;
				}

				.btn {
					width: 464rpx;
					height: 60rpx;
					background: #1DBE61;
					border-radius: 30rpx;
					font-size: 32rpx;
					color: #fff;
					display: flex;
					align-items: center;
					justify-content: center;
					margin-top: 150rpx;
				}
			}
		}

	}
</style>
